package thread;

public class Demo14 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = Thread.currentThread();//拿到main线程的引用
        Thread t2 = new Thread(() -> {
            try {
                t.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2结束");
        });
        t2.start();

        for (int i = 0; i < 5; i++) {
            Thread.sleep(1000);
        }
        System.out.println("main over");
    }
}//这种写法能拿到main的引用从而让其他线程等待main线程结束
